import 'package:flutter/material.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../base/view.dart';
import '../global/Global.dart';

class MenuPage extends StatefulWidget {
  const MenuPage({Key? key}) : super(key: key);

  @override
  _MenuPageState createState() => _MenuPageState();
}

class _MenuPageState extends State<MenuPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppbarActions('首页', [
        IconButton(onPressed: (){
            Navigator.of(context).pushNamed('/theme');
          },
            icon: Icon(Icons.settings))
      ],
      ),
      body: Column(
        children: [
          Container(
            height: 300,
            child: Swiper(
              itemBuilder: (BuildContext context, int index) {
                return new Image.network(
                  "https://img1.baidu.com/it/u=3792788009,4147546995&fm=11&fmt=auto&gp=0.jpg",
                  fit: BoxFit.fill,
                );
              },
              itemCount: 3,
              pagination: new SwiperPagination(),
              control: new SwiperControl(),
            ),
          ),
          RaisedButton(
              onPressed: () {
                Navigator.of(context).pushNamed('/accounting');
              },
            child: Text('记账'),
          ),
          RaisedButton(
              onPressed: () {
                Navigator.of(context).pushNamed('/imagePage');
              },
            child: Text('照片'),
          ),
        ],
      ),
      drawer: Drawer(
        child: ListView(
          padding: EdgeInsets.zero,
          children: [
            UserAccountsDrawerHeader(
              currentAccountPicture: Image.network('https://img2.baidu.com/it/u=2181840449,3378327568&fm=11&fmt=auto&gp=0.jpg'),
              accountName: Text("许先"),
              accountEmail: Text(
                "414467186@qq.com",
              ),
            ),
            ListTile(
              title: Text("支出上限"),
              subtitle: Text(Global().getInstance().user["money"].toString()),
              trailing: Icon(Icons.navigate_next),
              onTap: () {},
            ),
            Divider(height: 1),
            ListTile(
              title: Text("注册日期"),
              subtitle: Text(Global().getInstance().user["date"]),
              trailing: Icon(Icons.navigate_next),
              onTap: () {
                Navigator.pop(context);
              },
            ),
            Divider(height: 1),
            ListTile(
              title: Text("退出登陆"),
              trailing: Icon(Icons.exit_to_app),
              onTap: () async {
                SharedPreferences sp = await SharedPreferences.getInstance();
                sp.remove("token");
                Navigator.of(context).popAndPushNamed("/");
              },
            ),
          ],
        ),
      ),
    );
  }
}
